#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int T,n,maxn,a[N];
bool f[N];
void dfs(int i,int c){
    for(int j=i-1;j>=1;j--)
        if(f[i]==f[j]&&a[i]==a[j]){
            c+=a[i];maxn=max(maxn,c);
        }
    if(i==n)return;
    for(int j=0;j<=1;j++){
        dfs(i+1,c);f[i]=1;
        dfs(i+1,c);f[i]=0;
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        maxn=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        memset(f,0,sizeof(f));
        dfs(1,0);
        cout<<maxn<<endl;
    }
    return 0;
}
